{layout name="master" /}

<!--发布微博-->
<div id="pubmsg">
    <form action="javascript:;" method="post">
        <script id="editor" type="text/plain" style="width:598px;height:100px;margin-bottom:5px"></script>
        <!--<h2>有什么新鲜事想告诉大家？</h2>
        <textarea name="" rows="" cols=""></textarea>-->
        <button onclick="hasContent()" type="button" class="btn btn-primary">发布微博</button>
        <a href="{:url('pubarc')}" class="btn btn-success">发文章</a>
    </form>
</div>

<!--发布微博结束-->

{volist name="weibos" id="vo"}
<!--每一条微博的内容-->
<div class="center_con">
    <div class="c_c_header">
        <img src="__PUBLIC__/Home/IMG/xiaohua2.jpg" alt="" class="touxiang"/>
        <span class="title">{$vo['username']}</span>
        <span class="time">{:date('Y年m月d日 H:i:s',$vo['pubtime'])}</span>
        <span class="come">来自</span>
						<span class="device">
							分享按钮
						</span>
    </div>
    <!--微博主体内容-->
    <div class="c_c_con">
        {$vo['content']}
    </div>
    <!--微博底部-->
    <div class="c_c_footer">
        <div class="c_c_f_con">
            <ul>
                <li onclick="store({$uid},{$vo['wid']},this)" {if condition="($vo['isstore'] == 1)"} style="color: red" {/if}><i class=" icon-star-empty"></i>收藏</li>
                <li><i class="  icon-external-link"></i>转发</li>
                <li><i class="  icon-comment-alt"></i>评论</li>
                <li class="zan" onclick="nice({$vo['uid']},{$vo['wid']},this)" {if condition="($vo['isnice'] == 1)"} style="color: red" {/if}><i class="icon-thumbs-up"></i><span>{$vo['nices']}</span></li>
            </ul>
        </div>
    </div>
</div>
<!--每一条微博的内容结束-->
{/volist}


<script>
    toolbars = [
        ['fullscreen', 'source', 'undo', 'redo', 'bold']
    ];
    var ue = UE.getEditor('editor', toolbars);

    function hasContent() {
        var data = $('form').serialize();

        if (!UE.getEditor('editor').hasContents()) {
            alert('你填写内容');
        } else {
            $.ajax({
                type: "POST",
                url: "{:url('pub')}",
                data: data,
                dataType: "json",
                success: function (msg) {
                    if (msg != 0) {
                        var html = '<div class="center_con"> <div class="c_c_header"> ';
                        html += '<img src="__PUBLIC__/Home/IMG/xiaohua2.jpg" alt="" class="touxiang"/>';
                        html += '<span class="title">环球时报</span>';
                        html += '<span class="time">44分钟前</span>';
                        html += '<span class="come">来自</span>';
                        html += '<span class="device">分享按钮</span></div>';
                        html += '<div class="c_c_con">';
                        html += msg.content;
                        html += '</div> <div class="c_c_footer">';
                        html += '<div class="c_c_f_con"><ul>'
                        html += '<li><i class=" icon-star-empty"></i>收藏</li>'
                        html += '<li><i class="  icon-external-link"></i>转发</li>';
                        html += '<li><i class="  icon-comment-alt"></i>评论</li>';
                        html += '<li class="zan"><i class="icon-thumbs-up"></i><span>1</span></li> </ul>';
                        html += '</div> </div> </div>';
                        $('#pubmsg').after(html);
                        ue.setContent('');
                    } else {
                        alert('发布失败');
                    }
                }
            })
        }
    }

    //点赞异步
    function nice(uid,wid,that){
        $.ajax({
            type: "POST",
            url: "{:url('indexLogin/manage/nice')}",
            data: {uid:uid,wid:wid},
            dataType:'json',
            success: function(msg){
//                alert( "Data Saved: " + msg );
//                alert(msg.weibocounts);
//                console.log(that);
                $(that).children().eq(1).html(msg.weibocounts);
                $(that).children().eq(0).css({'color':'red'});
            }
        })
    }

    //异步收藏
    function store(uid,wid,that){
        $.ajax({
            type: "POST",
            url: "{:url('indexLogin/manage/store')}",
            data: {uid: uid, wid: wid},
            dataType: 'json',
            success: function (msg) {
                if(msg.valid!=0){
                    $(that).css({'color':'red'});
                }
            }
        })
    }

</script>
